package net.dgg.zz.production.chargeback.service;

import net.dgg.tmd.foundation.platform.datapermission.entity.DataAuthDTO;
import net.dgg.tmd.foundation.platform.datapermission.service.DataPermissionAssocService;
import net.dgg.zz.common.base.service.BaseService;
import net.dgg.zz.production.chargeback.dao.ZzAuditOrderDao;
import net.dgg.zz.production.vo.ChargeBackOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author 孙上峰
 * @ClassName 已退单<ZzChargeBcakController>
 * @despriction
 * @create 2018/08/17 10:33
 **/
@Service
public class ZzChargeBcakService extends BaseService {
    @Autowired
    private ZzAuditOrderDao zzAuditOrderDao;
    @Autowired
    private DataPermissionAssocService dataPermissionAssocService;


    /**
     * 查询分页列表
     *
     * @param map {codeName:模块名称}
     * @return List<ScProductOrder>
     */
    @Transactional(readOnly = true)
    public List<Map> queryAuditListPage(Map map) {
        DataAuthDTO dataAuthDTO = dataPermissionAssocService.selectAuthToConfigureRturnOrgIds("zzsc_sc_chargebcak");
        map.put("dataAuthDTO", dataAuthDTO);
        map.put("userAlias", "t");
        map.put("userColumn", "flow_user_id");
        map.put("deptAlias", "t");
        map.put("deptColumn", "flow_user_org_id");
        Integer count = this.zzAuditOrderDao.count(map);
        map.put("count", count);
        if (count <= 0) {
            return new ArrayList<Map>(0);
        }
        if (null == map.get("orderColumn")) {
            map.put("orderDir", "desc");
            map.put("orderColumn", "abandonReasonTime");
        }
        List<Map> listPage = zzAuditOrderDao.queryMap(map);
        map.put("count", count);
        return listPage;
    }

    /**
     * 根据条件查询记录-导出
     *
     * @param params
     * @return
     */
    public List<ChargeBackOrderVo> findByParamsList(Map params) throws Exception {
        List<ChargeBackOrderVo> voList = new ArrayList<>();
        List<Map> srList = this.queryAuditListPage(params);
        for (int i = 0; i < srList.size(); i++) {
            ChargeBackOrderVo vo = new ChargeBackOrderVo();
            vo.setSignOrgName(String.valueOf(srList.get(i).get("signOrgName") == null ? "" : srList.get(i).get("signOrgName")));
            vo.setOrderNo(String.valueOf(srList.get(i).get("orderNo") == null ? "" : srList.get(i).get("orderNo")));
            vo.setScProductOrderNo(String.valueOf(srList.get(i).get("scProductOrderNo") == null ? "" : srList.get(i).get("scProductOrderNo")));
            vo.setCustomerName(String.valueOf(srList.get(i).get("customerName") == null ? "" : srList.get(i).get("customerName")));
            vo.setBusinessProductName(String.valueOf(srList.get(i).get("businessProductName") == null ? "" : srList.get(i).get("businessProductName")));
            vo.setProductName(String.valueOf(srList.get(i).get("productName") == null ? "" : srList.get(i).get("productName")));
            vo.setSignTime(String.valueOf(srList.get(i).get("signTime") == null ? "" : srList.get(i).get("signTime")));
            vo.setSignUserName(String.valueOf(srList.get(i).get("signUserName") == null ? "" : srList.get(i).get("signUserName")));
            vo.setSignUserOrgName(String.valueOf(srList.get(i).get("signUserOrgName") == null ? "" : srList.get(i).get("signUserOrgName")));
            vo.setFlowUserName(String.valueOf(srList.get(i).get("flowUserName") == null ? "" : srList.get(i).get("flowUserName")));
            vo.setFlowUserOrgName(String.valueOf(srList.get(i).get("flowUserOrgName") == null ? "" : srList.get(i).get("flowUserOrgName")));
            vo.setCompanyName(String.valueOf(srList.get(i).get("companyName") == null ? "" : srList.get(i).get("companyName")));
            voList.add(vo);
        }
        return voList;
    }

}
